package com.ruoyi.control.service.impl;

import com.ruoyi.control.domain.VipWebsite;
import com.ruoyi.control.mapper.VipWebsiteMapper;
import com.ruoyi.control.service.VipWebsiteService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 会员网站表(VipWebsite)表服务实现类
 *
 * @author Jiuchengi
 * @since 2024-12-18 15:09:20
 */
@Service("vipWebsiteService")
public class VipWebsiteServiceImpl implements VipWebsiteService {
    @Resource
    private VipWebsiteMapper vipWebsiteMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param websiteId 主键
     * @return 实例对象
     */
    @Override
    public VipWebsite queryById(Long websiteId) {
        return this.vipWebsiteMapper.queryById(websiteId);
    }

    /**
     * 分页查询
     *
     * @param vipWebsite  筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<VipWebsite> queryByPage(VipWebsite vipWebsite, PageRequest pageRequest) {
        long total = this.vipWebsiteMapper.count(vipWebsite);
        return new PageImpl<>(this.vipWebsiteMapper.queryAllByLimit(vipWebsite, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param vipWebsite 实例对象
     * @return 实例对象
     */
    @Override
    public VipWebsite insert(VipWebsite vipWebsite) {
        this.vipWebsiteMapper.insert(vipWebsite);
        return vipWebsite;
    }

    /**
     * 修改数据
     *
     * @param vipWebsite 实例对象
     * @return 实例对象
     */
    @Override
    public VipWebsite update(VipWebsite vipWebsite) {
        this.vipWebsiteMapper.update(vipWebsite);
        return this.queryById(vipWebsite.getWebsiteId());
    }

    /**
     * 通过主键删除数据
     *
     * @param websiteId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long websiteId) {
        return this.vipWebsiteMapper.deleteById(websiteId) > 0;
    }
}
